# Maintainer: Yusuke Sasaki <y_sasaki@nuem.nagoya-u.ac.jp>

_realname=cppcheck
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.74
pkgrel=1
pkgdesc="static analysis of C/C++ code (mingw-w64)"
arch=('any')
url="http://cppcheck.sourceforge.net/"
license=('GPL3')
depends=()
makedepends=("${MINGW_PACKAGE_PREFIX}-docbook-xsl"
             "${MINGW_PACKAGE_PREFIX}-qt5")
optdepends=("${MINGW_PACKAGE_PREFIX}-qt5: cppcheck-gui"
            "${MINGW_PACKAGE_PREFIX}-python2-pygments: cppcheck-htmlreport")
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/danmar/cppcheck/archive/${pkgver}.tar.gz"
        '0010-change-language-files-path.patch')
sha256sums=('a7f9657bf458190ea1c994b95333d31d09420198ad8cd010c05d2194cc547fa0'
            'a15a73396a2fa346d29df52c3143b46618454d0bc0f12f0ad891d5a4a856cb56')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/0010-change-language-files-path.patch"
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"

  LANG='en_US.UTF-8' make \
    SRCDIR=build \
    CFGDIR=${MINGW_PREFIX}/share/cppcheck/cfg \
    HAVE_RULES=yes \
    LDFLAGS=-lshlwapi RDYNAMIC=

  make man \
    DB2MAN=${MINGW_PREFIX}/share/xml/docbook/xsl-stylesheets-1.79.1/manpages/docbook.xsl \
    CFGDIR=${MINGW_PREFIX}/share/cppcheck/cfg

  cd gui
  lrelease gui.pro
  qmake HAVE_RULES=yes
  make \
    SRCDIR=build \
    CFGDIR=${MINGW_PREFIX}/share/cppcheck/cfg \
    HAVE_RULES=yes
}

check() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # LANG='en_US.UTF-8' make test \
  #   SRCDIR=build \
  #   CFGDIR=${MINGW_PREFIX}/share/cppcheck/cfg \
  #   HAVE_RULES=yes \
  #   LDFLAGS=-lshlwapi RDYNAMIC=
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"

  LANG='en_US.UTF-8' make install \
    DESTDIR="${pkgdir}" \
    PREFIX="${MINGW_PREFIX}" \
    SRCDIR=build \
    CFGDIR=${MINGW_PREFIX}/share/cppcheck/cfg \
    HAVE_RULES=yes

  # man and COPYING
  install -Dpm644 cppcheck.1 "${pkgdir}${MINGW_PREFIX}/share/man/man1/cppcheck.1"
  install -Dpm644 COPYING    "${pkgdir}${MINGW_PREFIX}/share/licenses/cppcheck/COPYING"

  # GUI
  install -m755 build/gui/cppcheck-gui.exe "${pkgdir}${MINGW_PREFIX}/bin"
  install -d "${pkgdir}${MINGW_PREFIX}/share/cppcheck/cfg/lang"
  install -D cfg/* -t "${pkgdir}${MINGW_PREFIX}/share/cppcheck/cfg"
  install -D gui/*.qm -t "${pkgdir}${MINGW_PREFIX}/share/cppcheck/cfg/lang"
}

# vim: set ft=sh ts=2 sw=2 et :
